package cn.wolfcode.contorller;

import cn.wolfcode.luowowo.domain.Destination;
import cn.wolfcode.luowowo.domain.Destination;
import cn.wolfcode.luowowo.query.DestinationQuery;
import cn.wolfcode.luowowo.service.IDestinationService;
import cn.wolfcode.luowowo.service.IDestinationService;
import cn.wolfcode.luowowo.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/destination")
public class DestinationController {
    @Autowired
    private IDestinationService destinationService;
    
    //查询全部列表
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") DestinationQuery query){
        Page<Destination> page = destinationService.query(query);
    
        model.addAttribute("page",page);
        
        //通过前端传过来的父类id进行吐丝位置的返回数据
        List<Destination> toasts = destinationService.getToasts(query.getParentId());
        model.addAttribute("toasts",toasts);
        return "destination/list";
    }

    //更新简介方法
    @RequestMapping("/updateInfo")
    @ResponseBody
    /*前端传过来的是一个id与一个简介 所以可以用对象进行封装*/
    public Object updateInfo(Destination destination){
        //保存事件没有返回值
        destinationService.updateInfo(destination);
        /*成功返回信息*/
        return JsonResult.success();
    }



    
    //删除方法
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(String id){
        destinationService.delete(id);
        return JsonResult.success();
    }
    
    //前端查询
}
